<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>课程直播</title>
</head>
<body>
 <div class="mainContainer" >
        <video id="videoElement" controls autoplay width="680"  muted="muted" height="370"></video>
    </div>
 <br>
    
 <script src="/static/lib/flv/flv.min.js" type="text/javascript" ></script>
   <script>
   
   function getQueryVariable(variable){
          var query = window.location.search.substring(1);
          var vars = query.split("&");
          for (var i=0;i<vars.length;i++) {
                  var pair = vars[i].split("=");
                  if(pair[0] == variable){return pair[1];}
          }
          return(false);
   }
   var urlz= 'http://47.92.196.10:8080/live/1.flv';
      var vid=getQueryVariable("vid")
        var flvjs = window.flvjs
        var videoElementzzz  = document.getElementById('videoElement');
        var flvPlayer;
        if (flvjs.isSupported()) {
             flvPlayer = flvjs.createPlayer({
                type: 'flv',
                isLive : true,
                //url: 'http://47.92.196.10:8080/live/1.flv',//改为自己服务的地址
                
                url: urlz,
                
                //url: 'http://127.0.0.1:8080/live/rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk.flv',//改为自己服务的地址
            });
            flvPlayer.attachMediaElement(videoElementzzz );
            flvPlayer.load(); //加载
            flvPlayer.play();
        }
        function flv_start() {
        	flvPlayer.play();
        }
        function flv_pause() {
        	flvPlayer.pause();
        }
        function flv_destroy() {
        	flvPlayer.pause();
        	flvPlayer.unload();
        	flvPlayer.detachMediaElement();
        	flvPlayer.destroy();
        	flvPlayer = null;
        }
        flv_start();
        
         /* setInterval(() => {
            if (flvPlayer.buffered.length) {
              let end = flvPlayer.buffered.end(0);//获取当前buffered值
              let diff = end - flvPlayer.currentTime;//获取buffered与currentTime的差值
              if (diff >= 0.5) {//如果差值大于等于0.5 手动跳帧 这里可根据自身需求来定
            	  flvPlayer.currentTime = flvPlayer.buffered.end(0);//手动跳帧
             }
            }
          }, 2000); */ //2000毫秒执行一次 /**/
        
         /*  flvPlayer.on(flvjs.Events.ERROR, (errorType, errorDetail, errorInfo) => {
      		console.log("errorType:", errorType);
              console.log("errorDetail:", errorDetail);
              console.log("errorInfo:", errorInfo);
              //视频出错后销毁重新创建
               if (flvPlayer) {
                flvPlayer.pause();
                flvPlayer.unload();
                flvPlayer.detachMediaElement();
                flvPlayer.destroy();
                flvPlayer= null;
                this.createPlayer(videoElement, urlz);
              }
            }); */
          
          
          
        /*   flvPlayer.on("statistics_info", function (res) {
              if (this.lastDecodedFrame == 0) {
                this.lastDecodedFrame = res.decodedFrames;
                return;
              }
              if (this.lastDecodedFrame != res.decodedFrames) {
                this.lastDecodedFrame = res.decodedFrames;
              } else {
                  this.lastDecodedFrame = 0;
                  if (flvPlayer) {
                    flvPlayer.pause();
                    flvPlayer.unload();
                    flvPlayer.detachMediaElement();
                    flvPlayer.destroy();
                    flvPlayer= null;
                    this.createPlayer(videoElement, urlz);
                }
              }
            }); */
        
    </script>
</body>
</html>